package com.cw.DesignModel23.Structural.CompositePattern.Composite2;

import java.util.ArrayList;
import java.util.List;

/** 大学
 * University 就是 Composite角色 , 可以管理College
 */
public class University extends OrganizationComponent {

    List<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();

    /**
     * 构造器
     * @param name
     * @param des
     */
    public University(String name, String des) {
        super(name, des);
    }

    /**
     * 重写add
     * @param organizationComponent
     */
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        organizationComponents.add(organizationComponent);
    }

    /**
     * 重写remove
     * @param organizationComponent
     */
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public String getDes() {
        return super.getDes();
    }

    /**
     * print方法，就是输出 University 包含的学院
     */
    @Override
    protected void print() {
        // 先输出学校的名字
        System.out.println("--------------" + getName() + "--------------");
        // 遍历 organizationComponents，其实就是遍历出学校的学院
        for (OrganizationComponent organizationComponent : organizationComponents) {
            organizationComponent.print();
        }
    }

}

